package edu.hunan.cxb18.service.impl;

import edu.hunan.cxb18.mapper.ProductMapper;
import edu.hunan.cxb18.pojo.Product;
import edu.hunan.cxb18.pojo.ProductExample;
import edu.hunan.cxb18.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author AuthorName
 * @create 2020-04-22 11:36
 */
@Service
public class ProductServiceImpl implements ProductService {
    @Autowired
    private ProductMapper productMapper;
    @Override
    public List<Product> queryByHot(Integer size) {
        return productMapper.queryByHots(size);
    }

    @Override
    public List<Product> queryByNew(Integer size) {
        return productMapper.queryByAddtime(size);
    }

    @Override
    public Product queryById(Integer id) {
        return productMapper.selectByPrimaryKey(id);
    }

    @Override
    public Map<String, List<Product>> loadIndexProducts(Integer size) {
        Map<String, List<Product>> indexProducts = new HashMap<>();
        List<Product> hots = productMapper.queryByHots(size);
        List<Product> news = productMapper.queryByAddtime(size);
        indexProducts.put("hots",hots);
        indexProducts.put("news",news);
        return indexProducts;
    }
}
